Function Reference

_TS_TaskPropertiesGet

Lists all or specified properties of a Task or Task Definition and returns an array or string or writes the properties to the console.

#Include <TaskScheduler.au3>
_TS_TaskPropertiesGet($oService, $vTask[, $iFormat = 1[, $bIgnoreNoValues = False[, $sQuerySection = ""[, $sQueryProperties = ""]]]])

 

Parameters

$oService Task Scheduler Service object as returned by _TS_Open
$vTask Path and name or object of the Registered Task to process or a Task Definition object
$iFormat Format of the output. Can be one of the following values
1 - User friendly format (default). Please see Remarks
2 - Format you can use as input to _TS_TaskPropertiesSet (just the content of the array)
3 - Format you can use as input to _TS_TaskPropertiesSet (full AutoIt syntax to define the array - without XML and written to the console)
$bIgnoreNoValues [optional] If set to True properties without a value do not get returned (default = False)
$sQuerySection [optional] Name of the Scheduler object to retrieve the properties from. If set to "" all objects will be retrieved (default = "")
$sQueryProperties [optional] Comma separated list of properties to retrieve from $sSection. If set to "" all properties will be retrieved (default = "")

 

Return Value

Success: For $iFormat=1 or 2: Zero based two-dimensional array with the following information. Please see Remarks as well.
    0 - Section related to a COM object
    1 - Property name
    2 - Property value
    3 - Comment
Success: For $iFormat=3: Writes the AutoIt array definition to the console
Failure: Returns "" and sets @error
    1901 - Error returned by _TS_TaskGet. @extended is set to the COM error code. Most probably the Task could not be found

 

Remarks

For $iFormat = 1 if you only request a single property you will get a string holding the value of the property. Else you get an array as described above.
All data returned by the function is in the format as retrieved from the Taskscheduler object.
e.g. LogonType is of type Integer, UserId is returned as String.

 

Related

 

See Also

https://www.experts-exchange.com/articles/11326/VBScript-and-Task-Scheduler-2-0-Listing-Scheduled-Tasks.html

 

Example


#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <TaskScheduler.au3>
#include <Array.au3>

Global $sTaskname = "\Microsoft\Windows\Device Information\Device"

; *****************************************************************************
; Connect to the Task Scheduler Service
; *****************************************************************************
Global $oService = _TS_Open()
If @error <> 0 Then Exit MsgBox($MB_ICONERROR, "Task Scheduler UDF", "Error connecting to the Task Scheduler Service. @error = " & @error & ", @extended = " & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))

; *****************************************************************************
; Get the property to check if the Task has been enabled - in user friendly format
; *****************************************************************************
Global $vTaskProperties = _TS_TaskPropertiesGet($oService, $sTaskname, 1, False, "TASK", "Enabled")
If Not @error Then
    ; _ArrayDisplay($vTaskProperties, "_TS_TaskPropertiesGet - User friendly format")
    MsgBox($MB_ICONINFORMATION, "_TS_TaskPropertiesGet", "Value of property 'Enabled' in section 'TASK': " & $vTaskProperties)
Else
    MsgBox($MB_ICONERROR, "_TS_TaskPropertiesGet", "Returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
EndIf

; *****************************************************************************
; Get all properties of the PRINCIPAL sub-object
; *****************************************************************************
$vTaskProperties = _TS_TaskPropertiesGet($oService, $sTaskname, 1, True, "PRINCIPAL")
If Not @error Then
    _ArrayDisplay($vTaskProperties, "_TS_TaskPropertiesGet")
Else
    MsgBox($MB_ICONERROR, "_TS_TaskPropertiesGet", "Returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
EndIf

; *****************************************************************************
; List properties of a single Task - in the format used by _TS_TaskPropertiesSet
; *****************************************************************************
$vTaskProperties = _TS_TaskPropertiesGet($oService, $sTaskname, 2, True)
If Not @error Then
    _ArrayDisplay($vTaskProperties, "_TS_TaskPropertiesGet - format used by _TS_TaskProperiesSet")
Else
    MsgBox($MB_ICONERROR, "_TS_TaskPropertiesGet", "Returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
EndIf

; *****************************************************************************
; List properties of a single Task - write the AutoIt array definition to the console
; Ignore properties without values
; *****************************************************************************
$vTaskProperties = _TS_TaskPropertiesGet($oService, $sTaskname, 3, True)
If Not @error Then
    MsgBox($MB_ICONINFORMATION, "_TS_TaskPropertiesGet", "AutoIt array definition has been written to the console")
Else
    MsgBox($MB_ICONERROR, "_TS_TaskPropertiesGet", "Returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
EndIf

_TS_Close()